<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<c:choose>
<c:when test="${sessionScope.userInfo!=null }">
	
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<!-- <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> -->
	<script type="text/javascript">
	$(document).ready(function(){	//댓글 보기
			// $(table id).hide();
	var bno=${requestScope.bvo.no };
 	 		$.ajax({
				type:"POST",
				url:"${initParam.root}buyboard.do",
				data:"command=getCommentList&bno="+bno,
				dataType:"json",
				success:function(data){
					var comments="";
					//$(table id).show()
					//alert(data.comList.list[0].comment); 페이징빈 적용시
				 	$.each(data.comList,function(index, commentsVO){
				 		//<tr>
						comments+="<tr><td><b>"+commentsVO.memberVO.id+
									"</b></td><td>"+commentsVO.timePosted+
									"&nbsp; <img src=img/reply.jpg>"+
									"<a href=>답글</a> </td></tr>"+
									"<tr><td colspan=2>"+commentsVO.comment+
									"</td></tr>";		
					});//each
					$("#buyCommentList").html(comments);// tbody에 접근한후 append(comments);
 				}//success
			});//ajax

	//댓글 쓰기
	$("#buyAddCommentBtn").click(function(){
		alert($("#buyAddForm").serialize());
		var dataString = $("#buyAddForm").serialize();
		 $.ajax({
				type:"POST",
				url:"${initParam.root}buyboard.do?command=registerComment",
				/* data:$("#buyAddForm").serialize(), */
				data:"comment="+$("#buy_comment").val()
						+"&buyBoardVO.no="+${requestScope.bvo.no }
						+"&buyBoardVO.level="+${requestScope.bvo.level}, 
				//data:dataString,
				success:function(data){
					alert("test");
		 		return false;
				}//success
		});//ajax	
	}); //click 
										
	 $("#updateBtn").click(function(){
		if(confirm("게시글을 수정하시겠습니까?")){
			var nodata =${requestScope.bvo.no };
			location.href = "${initParam.root}buyboard.do?command=goUpdateView&no="+nodata;
		}else{
			return false;
			};
		}); //click
	$("#deleteBtn").click(function() {
		if(confirm("게시글을 삭제 하시겠습니까?")){
			var delno = ${requestScope.bvo.no };
			location.href = "${initParam.root}buyboard.do?command=deleteConetent&no="+delno;
		}else{
			return false;
		};
	}); //click
});//ready
	</script>
	<br>
		<b><font>${requestScope.bvo.title } </font></b>
				<br><br>
					글쓴이: ${requestScope.bvo.memberVO.name }(${requestScope.bvo.memberVO.id }) &nbsp;
					조회수: ${requestScope.bvo.hits } &nbsp;
					시간: ${requestScope.bvo.timePosted } &nbsp;
					<br>
					e-mail : ${requestScope.bvo.memberVO.email }
					<br>
					상품명 : ${requestScope.bvo.goods } &nbsp;
					거래지역 : ${requestScope.bvo.tradeArea } &nbsp;
				<br>
				<textarea rows="15px" cols="70px" readonly>${requestScope.bvo.content}
				</textarea>
				<br>
	<a href="${initParam.root}buyboard.do?command=getContentList&nowPage=1"><img alt="목록" border="0" src="img/list_btn.jpg" ></a>
	<a href="Javascript:$('updateBtn').click()"><img src="img/modify_btn.jpg" id="updateBtn"></a>
	<a href="Javascript:$('deleteBtn').click()"><img src="img/delete_btn.jpg" id="deleteBtn"></a>
	<br>
	<!-- 댓글 목록이 출력될 영역 -->
		<div id="buyCommentList">
			<!-- table 생성 <tbody> -->
		</div>  
		
	<!-- 댓글 입력 폼 -->
	<div id="buyCommentAdd">
	<hr>
		<form action="${initParam.root}buyboard.do" name="buyAddForm" id="buyAddForm" method="post"> 
		<!-- <form id="buyAddForm"> -->
		<input type="hidden" name="command" value="registerComment">
			내용: <textarea name="comment" cols="20" rows="2" id="buy_comment"></textarea> 
			<%-- <input type="hidden" name="buyBoardVO.no" value=${requestScope.bvo.no }>
			<input type="hidden" name="buyBoardVO.level" value=${requestScope.bvo.level }> --%>
			<a href="Javascript:$('buyAddCommentBtn').click()"><img src="img/btn-reply.gif" id="buyAddCommentBtn"></a>
		</form> </div>   
	
	<!-- 댓글 수정 폼 -->
	<!-- style="display: none" 으로 함으로써 처음에는 수정 폼이 보이지 않게 된다. -->
		<div id="buyCommentUpdate" style="display: none">  
		<form action="" name="updateForm">  
		<input type="hidden" name="id" value=""/>
			내용: <textarea name="content" cols="50px" rows="5px"></textarea><br/>  
		<input type="button" value="등록" id="buyUpdateCommentBtn"/> 
		<input type="button" value="취소" id="buyCancelUpdateBtn"/>  
		</form> 
		</div> 
	
	
</c:when>
<c:otherwise>
	<script type="text/javascript" >
		location.href="${initParam.root}view/index.jsp";
	</script>
</c:otherwise>
</c:choose>

